package com.wlr.study.leetcode;

/**
 * 移除链表元素
 *
 * @author HustleLr
 * @version 1.0.0
 * @date 2024/1/22 18:48
 * @describe LeetCode203
 */
public class LeetCode203 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dummy = new ListNode(-1, head);
        ListNode curr = dummy;
        while (curr.next != null) {
            if (curr.next.val == val) {
                curr.next = curr.next.next;
            } else {
                curr = curr.next;
            }
        }
        return dummy.next;
    }

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1, new ListNode(2, new ListNode(6, new ListNode(3, new ListNode(4, new ListNode(5, new ListNode(6)))))));
        ListNode listNode1 = new ListNode(7, new ListNode(7, new ListNode(7, new ListNode(7, new ListNode(7, new ListNode(7, new ListNode(7)))))));
        LeetCode203 leetCode203 = new LeetCode203();
        System.out.println(leetCode203.removeElements(listNode, 6));
    }
}
